$(function () {
  var oWebControl;
  var fontSize = $$.fitFontSize(16);
  var plynDatas; //行政区划
  var plyn, marker;
  var mapPlyns = [],
    mouseLnglat; //地图区块数组
  // var mapAreaCode = "330000"; //区划关键点
  var commonYear = new Date().getFullYear();

  var urlAreaCode = $$.localName('areaCode');
  var urlAreaName = $$.localName('areaText');
  var mapAreaCode = urlAreaCode ? urlAreaCode :'330000'; //区划关键点

  var isMapScale = false;
  var isMapClick = false;
  var mapLastZoom;
  var scrollckTimer = null;
  var scrollTimer = null;
  var fh_btn = false; //tab点击切换
  $("[page-href]").click(function () {
    var src = $(this).attr("page-href");
    window.parent.changeMainPage(src);
  });
  //地图指标类型
  var mapTypes = {
    main: [
      // {name:'在办案件',value:'zbajs'},
      // {name:'双随机检查次数',value:'ssjsjccs'}

      { name: "在办案件", value: 1 },
      // { name: "仲裁按期结案率", value: 2 },
      // { name: "网络办案率", value: 3 },
      // { name: "调解结案率", value: 4 },
    ],
  };
  var mapLevelSelects = {
    main_zbajs: [
        { lt: 90, class: 'green' },
        { lt: 189, gt: 90, class: 'yellow' },
        { gt: 200, class: 'red' },
        
    ],
    // main_ssjsjccs: [
    //     { gt: 100, class: 'green' },
    //     { lt: 100, gt: 10, class: 'yellow' },
    //     { lt: 10, class: 'red' },
    // ],
}

  var mapColor = {
    normal: "rgba(56,108,161,0.60)",
    active: "rgba(89,147,212,1)",
  };
  $(".model_tab span").on("click", function () {
    $(this).addClass("active").siblings().removeClass("active");
    var type = $(this).attr("data-type");
  });
  //所属管辖
  var areaDatas = [
      { label: "浙江省", value: "330000" },
      { label: "杭州市", value: "330100" },
      { label: "宁波市", value: "330200" },
      { label: "温州市", value: "330300" },
      { label: "嘉兴市", value: "330400" },
      { label: "湖州市", value: "330500" },
      { label: "绍兴市", value: "330600" },
      { label: "金华市", value: "330700" },
      { label: "衢州市", value: "330800" },
      { label: "舟山市", value: "330900" },
      { label: "台州市", value: "331000" },
      { label: "丽水市", value: "331100" },
    ],
    areaSelects = [];
  var sjgjPageTimer = null;

  // 顶部区划
  if(urlAreaCode){
    $(".map_tit span").attr('data-i',urlAreaCode);
    $(".map_tit span").text(urlAreaName);
  } 

  var myGDMap = new AMap.Map("map", {
    resizeEnable: true,
    rotateEnable: true,
    pitchEnable: true,
    zoom: 8,
    pitch: 45,
    // mapStyle: "amap://styles/dark",
    // mapStyle:'amap://styles/1c4fb1696d4e7344252ebc6334365e0c',
    mapStyle: "amap://styles/2b4440833495a1a629cd5595fec460c2",
    rotation: 0,
    // viewMode:'3D',//开启3D视图,默认为关闭
    buildingAnimation: true, //楼块出现是否带动画
    expandZoomRange: true,
    center: areaCenter[$$.handleQXCode(mapAreaCode)].center,
    zooms: areaCenter[$$.handleQXCode(mapAreaCode)].zooms,
  });
  var mapActiveAreaData = {};
  // AMap.plugin([
  //     'AMap.ToolBar',
  // ], function () {
  //     // 在图面添加工具条控件，工具条控件集成了缩放、平移、定位等功能按钮在内的组合控件
  //     myGDMap.addControl(new AMap.ToolBar({
  //         // 简易缩放模式，默认为 false
  //         liteStyle: false
  //     }));
  // });
  $(document).mousemove(function (e) {
    //获取鼠标位置，转成经纬度（区域放大下钻）
    e = e || window.event;
    // 容器坐标，原点为左上角
    var px = e.pageX;
    var py = e.pageY;
    // 构造成 Pixel 对象后传入
    mouseLnglat = myGDMap.containerToLngLat(new AMap.Pixel(px, py));
  });

  $(".map_tit .loc").live("click", function () {
    // 下钻记录点击
    mapAreaCode = $(this).attr("data-i");
    var mapLevel = getAreaLevel(mapAreaCode);
    $(this).nextAll().remove();
    $(this).addClass("active");
    if (mapLevel == 0) {
      myGDMap.setZoomAndCenter(8, [120.153576, 29.289523]);
      setModelMain();
    } else if (mapLevel == 1) {
      myGDMap.setZoomAndCenter(9, [mapActiveAreaData.x, mapActiveAreaData.y]);
      setModelMain();
    } else if (mapLevel == 2) {
      setModelMain();
    }
  });
  $('.backToOriginal').click(function () {//地图 回归定位点
    mapAreaCode = mapAreaCode;
    myGDMap.setZoomAndCenter(8, areaCenter[$$.handleQXCode(mapAreaCode)].center);
    $('.map_tit .loc').eq(0).nextAll().remove();
    setModelMain();
  })
  
  //地图 放大
  $(".add").click(function () {
    var zoom = myGDMap.getZoom();
    if (zoom < 20) {
      myGDMap.zoomIn();
    }
  });
  //地图 缩小
  $(".del").click(function () {
    var zoom = myGDMap.getZoom();
    if (zoom > 7) {
      myGDMap.zoomOut();
    }
  });
  layui.use(["form", "laydate"], function () {
    var laydate = layui.laydate;
    //年选择器
    laydate.render({
      elem: "#year",
      type: "year",
      value: new Date().getFullYear(),
      min: -366,
      max: 0,
      done: function (value, date) {
        commonYear = value;
        setModelMain();
      },
      // change: function(value, date){ //监听日期被切换
      //     commonYear = value;
      //     setModelMain()
      // }
    });
  });
  $(".block_name").live("click", function () {
    var childModelClick = $(this).attr("data-model");
    if (childModelClick) {
      $(".tablist .tab_item.active").attr("child-model-click", childModelClick);
    } else {
      $(".tablist .tab_item.active").attr("child-model-click", "");
    }
  });

 

  var zcyjgList = [];
  var cxfwList = [];
  getzcyjgList()// 获取仲裁机构字典 设置为同步方法
  function getzcyjgList(){
     $$.ajaxRequest( ajaxUrl2 + "/lemis/business/dp/tsInterface",
         {
           method: "queryTheDictionary",
           source: 3,
           dType: 1,
         },
         function (res) {
             console.log(res.data,"datat")
             if(res.data && res.data.length>0){
                 zcyjgList = [{
                     id: "1",
                     title: "浙江省劳动人事争议仲裁院",
                     child: getChildren('1',res.data)
                 }]
             }

         }
       );
  }
  function getChildren(areacode,data){
    var child = [];
    $.each(data,function(i,item){
        if(item.pid == areacode){
            child.push({
                id: item.id,
                pid: item.pid||'',
                title: item.name,
                child: getChildren(item.id,data)
            });
        }
    })
    return child;
}
  // 获取查询范围字典
  $$.ajaxRequest(
    ajaxUrl2 + "/lemis/business/dp/tsInterface",
    {
      method: "queryTheDictionary",
      source: 3,
      dType: 2,
      aaa100: "CXFW",
    },
    function (res) {
      let data = res.data;
      data.forEach((item) => {
        let obj = {};
        obj.label = item.aaa103;
        obj.value = item.aaa102;
        cxfwList.push(obj);
      });
    },
    () => {},
    "post",
    false
  );

  // alertMaptable(title,mapAreaCode,commonYear);
  function alertMaptable(title, mapAreaCode, commonYear, abz345, cxfw, abb017Start, abb017End, czjg, month,zbaj,isblz,isbjs) {

    $$.alertTable({
      title: title,
      colsData: [
        [
          { title: "序号", type: "numbers" },
          { title: "案号", field: "abb016" },
          { title: "申请人", field: "abb703" },
          { title: "被申请人", field: "abb704" },
          { title: "仲裁员(申请接待员)", field: "pop1_1" },
        ],
      ],
      url: ajaxUrl2 + "/lemis/business/dp/tsInterface?method=caseList&source=3&administrativeDivisionCode=" + mapAreaCode + "&year=" + commonYear + "&mType=2",
      where: {
        abz345: abz345 || "",
        cxfw: cxfw || "",
        abb017Start: abb017Start || "",
        abb017End: abb017End || "",
        czjg: czjg || "",
        month: month || "",
        zbaj:zbaj||"",
        isblz:isblz||"",
        isbjs:isbjs||""
      },
      pageProp: {
        limit: 10,
      },
      searchColumn: [
        {
          name: "所属仲裁机构",
          field: "abz345",
          type:'dropdown',
          dicData: zcyjgList,
        },
        {
          name: "查询范围",
          field: "cxfw",
          type: "select",
          dicData: cxfwList,
        },
        { name: "立案时间起", field: "abb017Start", type: "datePicker", range: false, subtype: "date", format: "yyyy年MM月dd日" },
        { name: "立案时间至", field: "abb017End", type: "datePicker", range: false, subtype: "date", format: "yyyy年MM月dd日" },

        // 多级
        // { name: "地域", field: "aab301", type: "dropdown", dicData: areaSelects },
        // {name: "状态", field: "yja011", type: "select",dicData: [{ label:'正在处理',value:'1'},{ label:'已办结',value:'2'}]},
      ],
      rowClickFun: function (obj) {
        let data = obj.data.abz301;
        alertZBAJDetails(data);
      },
    });
  }

  function alertZBAJDetails(data) {
    var tableColumns = [
        [
        { title: "案号", field: "abb016" },
        { title: "被申请人", field: "abb704" },
        { title: "申请人", field: "abb703" },
        { title: "申请类型", field: "bbb705name" },
        { title: "案件来源", field: "ajly" },
        { title: "仲裁员", field: "abb782name" },
        { title: "书记员", field: "abb785name" },
        { title: "立案日期", field: "abb017" },
        { title: "案件进行天数", field: "day1" },
        ],
        [
        { title: "仲裁请求", field: "abb878" },
        { title: "仲裁事实和理由", field: "abb712" },
        ],
    ];
    var ecm = $$.alert("axzs");
    $("#" + ecm).html(`     
                <div class="title aj">案件详情</div>         
                <div class="table_con ajxq">         
                    <div class="model">         
                        <div class="detail_title">基本信息&nbsp;&nbsp;</div>        
                        <div class="model_content ztxxTable"></div>    
                    </div>
                    <div class="model">        
                        <div class="detail_title long_bg">&nbsp;&nbsp;&nbsp;&nbsp;劳动者（申请人）</div>         
                        <div class="news ztxxTable1"></div>        
                    </div>

                    <div class="model">         
                        <div class="detail_title long_bg">&nbsp;&nbsp;&nbsp;用人单位（被申请人）</div>       
                        <div class="news ztxxTable2"></div>     
                    </div>
                    
                    <div class="model">         
                        <div class="detail_title">申请信息&nbsp;&nbsp;</div>       
                        <div class="model_content ztxxTable3"></div>     
                    </div>

                    <div class="model">         
                        <div class="detail_title long_bg">&nbsp;&nbsp;&nbsp;办事记录
                        </div>       
                        <div class="news bsjl ztxxTable5"></div>     
                    </div>
                </div>
            `);


      $$.ajaxRequest(
        ajaxUrl2 + "/lemis/business/admin/queryHitoricInfo",
        {
            abz301: data,
            type:1,
            source: 3,
        },
        function (res) {
        var list = res.root;
        // 数据处理
        var blackList = ["开始","结束","立案审批","结案审批"];
        list = list
        .filter((item) => item.activityName&&blackList.indexOf(item.activityName) == -1)
        .map((item) => {
            return {
                assign_name: item.assign_name.includes("red") ? item.assign_name.replaceAll("<span  style=\"color:red\">","") : item.assign_name,
                endTime: item.endTime,
                startTime: item.startTime,
                activityName: $$.handleActivityName(item.activityName),
            };
        });
        // 倒序
        list = list.reverse();

        gettablePhb({
            tableId: ".ztxxTable5",
            autoScroll: false,
            time: 2500,
            imgIndex: false,
            scrollName: scrollckTimer,
            columns: [
            { title: "序号", type: "index",width: "4%" },
            { title: "环节名称", field: "activityName",width: "24%" },
            { title: "办理人", field: "assign_name",width: "24%" },
            { title: "开始时间", field: "startTime",width: "24%" },
            { title: "结束时间", field: "endTime",width: "24%" }
            ],
            data: list,
        });
    })
    
    $$.ajaxRequest(
        ajaxUrl2 + "/lemis/business/dp/tsInterface",
        {
        abz301: data,
        method: "caseDetails",
        source: 3,
        },
        function (res) {
        var data = res.data || {};
        $$.title3Table("#" + ecm + " .ztxxTable", tableColumns[0], data.bybusorabz301 || {}, 3);

        gettablePhb({
            tableId: ".ztxxTable1",
            autoScroll: false,
            time: 2500,
            imgIndex: false,
            scrollName: scrollckTimer,
            columns: [
            { title: "序号", type: "index",width: "5%" },
            { title: "劳动者姓名", field: "aac003" },
            { title: "证件号码", field: "aac002" },
            { title: "性别", field: "aac004" },
            { title: "联系电话", field: "aae005" },
            { title: "通讯地址", field: "bae198" },
            ],
            data: [data.beyondcasedetailsbasic],
        });

        gettablePhb({
            tableId: ".ztxxTable2",
            autoScroll: false,
            time: 2500,
            imgIndex: false,
            scrollName: scrollckTimer,
            columns: [
            { title: "序号", type: "index",width: "5%" },
            { title: "单位名称", field: "aab004" },
            { title: "法定代表人", field: "aab013" },
            { title: "法定代表人职务", field: "aab502" },
            { title: "法定代表人联系电话", field: "aab015" },
            { title: "联系人", field: "aab503" },
            { title: "联系人联系电话", field: "aab505" },
            { title: "通讯地址", field: "bae198" },
            { title: "单位性质", field: "aab019" },
            ],
            data: [data.beyondcasedetailsrespondent],
        });

        $$.title3Table("#" + ecm + " .ztxxTable3", tableColumns[1], data.bybusorabz301 || {}, 1);
        // $$.title2Table("#" + ecm + " .ztxxTable2", tableColumns[0], data || {}, 2);

        // if(data.yja011-0 == 2){

        //     $$.title2Table('#'+ecm+' .jbqkTable', tableColumns[2], data||{},2);

        // }else{

        //     $('#'+ecm+' .czqk').hide();

        // }
        }
    );
    }

  //初始化
  setModelMain();
  function setModelMain(notRenderMap) {
    $('#year').val(commonYear)
    //TODO: 首页
    setMapTypeSelects();
    if (!notRenderMap) {
      initMap(); //初始化地图调用
    }
    // 案件办理情况
    $$.ajaxRequest(
      ajaxUrl2 + "/lemis/business/dp/tsInterface",
      {
        method: "speedAndCuttingOne",
        source: 3,
        administrativeDivisionCode: mapAreaCode,
        year: commonYear,
        
      },
      function (res) {
        let data = res.data;
        setZBData(".ajblzb", data, function () {
          $(".ajblzb [data-key]").on("click", function () {
            let title = $(this).parent().prev().text();
            let a = $(this).attr("data-key");
            if (a == "djs") {
              alertMaptable(title, mapAreaCode, commonYear);
            }else if(a=="blz"){
              alertMaptable(title, mapAreaCode, commonYear, "", "", "", "", "", "","",1)
             
            }else if(a=="bjs"){
              alertMaptable(title, mapAreaCode, commonYear, "", "", "", "", "", "","","",1)
            }
          });
        });
      }
    );

    // 案件趋势按月
    $$.ajaxRequest(
      ajaxUrl2 + "/lemis/business/dp/tsInterface",
      {
        method: "speedAndCuttingTwo",
        source: 3,
        dType: 1,
        administrativeDivisionCode: mapAreaCode,
        year: commonYear,
        
      },
      function (res) {
        let data = res.data;
        let keys = data.map((item) => item.key);
        let categories = data.map((item) => item.name);
        let valueArr = data.map((item) => item.value);
        setLine(
          "#ajqsay",
          {
            unit: "件",
            categories: categories,
            series: [{ name: "数量", data: valueArr }],
          },
          { color: ["#34C39D"], hideArea: true },
          function (params) {
            var index = res.data.map((item) => item.name).indexOf(params.name);
            alertMaptable(params.name, mapAreaCode, commonYear, "", "", "", "", "", keys[index]);
          }
        );
      }
    );

    // 案件处理结果
    $$.ajaxRequest(
      ajaxUrl2 + "/lemis/business/dp/tsInterface",
      {
        method: "speedAndCuttingThree",
        source: 3,
        administrativeDivisionCode: mapAreaCode,
        year: commonYear,
       
      },
      function (res) {
        let data = res.data;
       
        moreBar("#moreBar", { datas: data, unit: "件" }, {}, function (params) {
          var index = res.data.map((item) => item.name).indexOf(params.name);
          alertMaptable(params.name, mapAreaCode, commonYear, "", "", "", "", data[index].key);
        });
      }
    );

    // 最新办件
    $$.ajaxRequest(
      ajaxUrl2 + "/lemis/business/dp/tsInterface",
      {
        method: "speedAndCuttingFive",
        source: 3,
        administrativeDivisionCode: mapAreaCode,
        year: commonYear,
        
      },
      function (res) {
        gettablePhb(
          {
            tableId: "#tableId",
            autoScroll: false,
            tableClickType:2,
            time: 2500,
            imgIndex: false,
            scrollName: scrollckTimer,
            columns: [
              { title: "时间", field: "abb017" },
              { title: "案件名称", field: "abb016" },
              { title: "仲裁员", field: "pop1_1" },
            ],
            data: res.data.list,
          }
        );
      }
    );

    // 平均审限
    $$.ajaxRequest(
      ajaxUrl2 + "/lemis/business/dp/tsInterface",
      {
        method: "speedAndCuttingSix",
        source: 3,
        administrativeDivisionCode: mapAreaCode,
        year: commonYear,
        
      },
      function (res) {
        let data = res.data;
        setBar(
          "#pjsxbar",
          {
            unit: "天",
            categories: data.map((item) => item.name),
            series: [{ name: "天数", data: data.map((item) => item.value) }],
          },
          { color: [{ color1: "#15C0FF", color2: "#15C0FF" }] }
        );
      }
    );

    // 调解率对比
    $$.ajaxRequest(
      ajaxUrl2 + "/lemis/business/dp/tsInterface",
      {
        method: "speedAndCuttingSeven",
        source: 3,
        administrativeDivisionCode: mapAreaCode,
        year: commonYear,
        dType: 1,
       
      },
      function (res) {
        let data = res.data;

        setybp("#tjlv1", {
          title: data.name,
          progress: {
            colorStops: ["#57A2FF", "#57A2FF"],
          },
          detail: {
            color: "#57A2FF",
          },
          axisTick: {
            color: "#57A2FF",
          },
          axisLine: {
            color: ["rgba(87, 162, 255,.2)", "rgba(87, 162, 255,0)"],
          },
          value: data.num,
        });
      }
    );

    $$.ajaxRequest(
      ajaxUrl2 + "/lemis/business/dp/tsInterface",
      {
        method: "speedAndCuttingSeven",
        source: 3,
        administrativeDivisionCode: mapAreaCode,
        year: commonYear,
        dType: 2,
       
      },
      function (res) {
        let data = res.data;

        setybp("#tjlv2", {
          title: data.name,
          progress: {
            colorStops: ["#24CFBD", "#24CFBD"],
          },
          detail: {
            color: "#57A2FF",
          },
          axisTick: {
            color: "#57A2FF",
          },
          axisLine: {
            color: ["rgba(87, 162, 255,.2)", "rgba(87, 162, 255,0)"],
          },
          value: data.num,
        });
      }
    );

    // 结案率对比
    $$.ajaxRequest(
      ajaxUrl2 + "/lemis/business/dp/tsInterface",
      {
        method: "speedAndCuttingEight",
        source: 3,
        administrativeDivisionCode: mapAreaCode,
        year: commonYear,
        dType: 1,
       
      },
      function (res) {
        let data = res.data;
        setybp("#jalv1", {
          title: data.name,
          progress: {
            colorStops: ["#24CFBD", "#24CFBD"],
          },
          detail: {
            color: "#57A2FF",
          },
          axisTick: {
            color: "#57A2FF",
          },
          axisLine: {
            color: ["rgba(87, 162, 255,.2)", "rgba(87, 162, 255,0)"],
          },
          value: data.value,
        });
      }
    );

    // 最新案件更多
    $('#zxanj_more').on('click',function(){
        alertZXAJtable("最新案件")
    })

    $$.ajaxRequest(
      ajaxUrl2 + "/lemis/business/dp/tsInterface",
      {
        method: "speedAndCuttingEight",
        source: 3,
        administrativeDivisionCode: mapAreaCode,
        year: commonYear,
        dType: 2,
        
      },
      function (res) {
        let data = res.data;
        setybp("#jalv2", {
          title: data.name,
          progress: {
            colorStops: ["#57A2FF", "#57A2FF"],
          },
          detail: {
            color: "#57A2FF",
          },
          axisTick: {
            color: "#57A2FF",
          },
          axisLine: {
            color: ["rgba(87, 162, 255,.2)", "rgba(87, 162, 255,0)"],
          },
          value: data.value,
        });
      }
    );
  }



  // 最新案件更多列表
  function alertZXAJtable(title,params,abb017Start,abb017End,abz345,cxfw){
    params= params||{}
     if(!params.administrativeDivisionCode){
       params.administrativeDivisionCode=mapAreaCode
     }
     if(!params.year){
       params.year=commonYear
     }
   var where={
       mType: 1,
         abz345: abz345 || '',
         cxfw: cxfw || '',
         abb017Start:abb017Start || '',
         abb017End:abb017End || ''
       }
   $$.alertTable({
       title: title,
       colsData: [
         [
           { title: "序号", type: "numbers" },
           { title: "案号", field: "abb016" },
           { title: "申请人", field: "abb703" },
           { title: "被申请人", field: "abb704" },
           { title: "仲裁员(申请接待员)", field: "pop1_1"},
         ],
       ],
       url: ajaxUrl2 + "/lemis/business/dp/tsInterface?method=caseList&source=3&zxbj=1&mType=2",
       where: Object.assign(params,where),
       pageProp: {
         limit: 10,
       },
       searchColumn: [
         {
           name: "所属仲裁机构",
           field: "abz345",
           type:'dropdown',
           dicData: zcyjgList,
         },
         {
           name: "查询范围",
           field: "cxfw",
           type: "select",
           dicData: cxfwList,
         },
         { name: "立案时间起", field: "abb017Start", type: "datePicker", range: false, subtype: "date", format: "yyyy年MM月dd日" },
         { name: "立案时间至", field: "abb017End", type: "datePicker", range: false, subtype: "date", format: "yyyy年MM月dd日" },
       ],
       rowClickFun: function (obj) {
           let data = obj.data.abz301;
           alertZBAJDetails(data);
        
       },
     });
}

  // function gettablePhb(config, callback) {
  //   var id = config.tableId || "";
  //   var columns = config.columns || [];
  //   var datas = config.data || [];
  //   var scrollName = config.scrollName;
  //   var html = '<div class="tbody">';
  //   var head_html_ = `<div class="thead"><div class="t_tr">`;
  //   $.each(columns, function (i, item) {
  //     head_html_ += '<div class="text_overflow" style="width:' + (item.width || "calc(100% / " + columns.length + ")") + '" title="' + item.title + '">' + item.title + "</div>";
  //   });
  //   head_html_ += ` </div></div>`;
  //   $.each(datas, function (i, item) {
  //     // 每行data中放入案件id
  //     html += ` <div data-clkey=${item.ajid} class="t_tr tr tnr" >`;
  //     $.each(columns, function (j, jItem) {
  //       if (jItem.type == "index") {
  //         if (config.imgIndex) {
  //           html += `<div style="width:${jItem.width ? jItem.width : "calc(100% /" + columns.length + ")"}">
  //                       <i class="pm pm_box pm_${i + 1}"><span>top${i > 9 ? i + 1 : "0" + (i + 1)}</span></i></div>`;
  //         } else {
  //           html += `<div style="width:${jItem.width ? jItem.width : "calc(100% /" + columns.length + ")"}">
  //                       <i class=" pm_box "><span>${i + 1}</span></i></div>`;
  //         }
  //       } else {
  //         html += `<div style="width:${jItem.width ? jItem.width : "calc(100% /" + columns.length + ")"}"  title="${item[jItem.field] || ""}${jItem.unit ? jItem.unit : ""}" >
  //                      ${item[jItem.field] || ""}${jItem.unit ? jItem.unit : ""}</div>`;
  //       }
  //     });
  //     html += `</div>`;
  //   });
  //   html += `</div>`;
  //   if (datas.length > 0) {
  //     $(id).html(head_html_ + html);
  //   } else {
  //     $(id).html(head_html_ + `<div style=" text-align: center;">暂无数据</div>`);
  //   }
  //   if (config.autoScroll) {
  //     clearInterval(scrollName);
  //     scrollName = $(id + " .tbody").scrollTable2({
  //       interval: config.time,
  //       scrollByRow: true,
  //     });
  //   }
  //   // callback && callback(data);
  //   callback && callback();
  // }


  function gettablePhb(config) {
    var id = config.tableId || ''
    var columns = config.columns || []
    var datas = config.data || [];
    var scrollName = config.scrollName;
    var html = '<div class="tbodyBox"><div class="tbody">';
    var head_html_ = `<div class="thead"><div class="t_tr">`
    $.each(columns, function (i, item) {
        head_html_ += '<div class="text_overflow" style="width:' + (item.width || 'calc(100% / ' + columns.length + ')') + '" title="' + item.title + '">' + (item.title) + '</div>'
    })
    head_html_ += ` </div></div>`
    $.each(datas, function (i, item) {
        html += ` <div class="t_tr tr" data-i="${i}">`
        $.each(columns, function (j, jItem) {
            if (jItem.type == 'index') {
                if (config.imgIndex) {
                    html += `<div style="width:${jItem.width ? jItem.width : 'calc(100% /' + columns.length + ')'}">
                    <i class="pm pm_box pm_${i + 1}"><span>top${i > 9 ? i + 1 : '0' + (i + 1)}</span></i></div>`
                } else {
                    html += `<div style="width:${jItem.width ? jItem.width : 'calc(100% /' + columns.length + ')'}">
                    <i class=" pm_box "><span>${i + 1}</span></i></div>`
                }

            } else {
                html += `<div style="width:${jItem.width ? jItem.width : 'calc(100% /' + columns.length + ')'}"  title="${(item[jItem.field] || '')}${jItem.unit ? jItem.unit : ''}" >
                    ${(item[jItem.field] || '')}${jItem.unit ? jItem.unit : ''}</div>`
            }
        })
        html += `</div>`
    });
    html += `</div></div>`
    if (datas.length > 0) {
        $(id).html(head_html_ + html);
    } else {
        $(id).html(head_html_ + `<div style=" text-align: center;">暂无数据</div>`);
    }
    $(id+" .tr").on("click",function(){
        var index=$(this).attr("data-i")
        var id=datas[index].abz301||''
        if(config.tableClickType==2){
            alertZBAJDetails(id);
        }else if(config.tableClickType==true){
            config.funClick&&config.funClick(datas[index])
        }
        
    })
    if (config.autoScroll&&datas.length>3) {
        console.log(config.time, "config.time",)
        clearInterval(scrollName)
        scrollName = $(id + ' .tbody').scrollTable2({
            interval: config.time,
            scrollByRow: true,
        })
    }
}

  function setBarOrLine(id, data, option, clickFun) {
    option = option || {};
    var elem = $(id)[0];
    var myChart = echarts.getInstanceByDom(elem) || echarts.init(elem);
    var datas = data.series,
      series = [],
      unit = data.unit;
    var color = option.color || [
      { color2: "", color1: "#15C0FF" },
      { color2: "", color1: "#34C39D" },
      { color2: "", color1: "#FF6169" },
      { color2: "", color1: "#FFBD1E" },
    ];
    var chartType = "";
    datas.map((item, i) => {
      chartType = item.type || "line";
      series.push({
        animation: true,
        name: item.name,
        stack: item.stack || "",
        type: item.type,
        data: item.data,
        barWidth: option.barWidth || 10,
        // barMinHeight: (option.barWidth||10)/3,
        itemStyle: {
          color:
            item.type == "line"
              ? color[i].color1
              : new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: color[i].color1,
                  },
                  {
                    offset: 1,
                    color: color[i].color2 || color[i].color1,
                  },
                ]),
        },
        yAxisIndex: item.yAxisIndex || 0,
        symbol: "circle",
        symbolSize: 4,
        smooth: true,
        lineStyle: {
          width: 2,
          color: color[i].color1,
        },
      });
    });
    var myOption = {
      grid: {
        left: 0,
        top: $$.transVHFontSize(1.7 + 1.7),
        bottom: 0,
        right: 0,
        containLabel: true,
      },
      tooltip: {
        show: true,
        trigger: "axis",
        confine: true,
      },
      legend: {
        show: true,
        left: option.twoYAxis ? "center" : "right",
        top: 0,
        itemWidth: $$.transVHFontSize(1.2),
        itemHeight: $$.transVHFontSize(0.8),
        itemGap: $$.transVHFontSize(2),
        textStyle: {
          fontSize: fontSize,
          color: "#fff",
        },
      },
      xAxis: [
        {
          type: "category",
          axisLabel: {
            interval: 0,
            formatter: "{value} ",
            color: "#ffffff",
            textStyle: {
              fontSize: fontSize,
            },
            rotate: option.xAxisRotate || 0,
          },
          boundaryGap: true,
          interval: 0,
          data: data.categories,
          axisLine: {
            show: true,
            lineStyle: {
              color: "#4F6776",
            },
          },
          axisTick: {
            show: true,
            lineStyle: {
              color: "#4F6776",
            },
          },
          splitLine: {
            show: option["yAxisSplitLineShow"] || false,
            lineStyle: {
              type: "dotted",
              width: 0.5,
              color: "#4F6776",
            },
          },
        },
      ],
      yAxis: [
        {
          type: "value",
          axisLabel: {
            formatter: "{value} ",
            color: "#ffffff",
            textStyle: {
              fontSize: fontSize,
            },
          },
          name: unit[0] ? "单位：" + unit[0] : "",
          nameGap: $$.transVHFontSize(1.2),
          nameTextStyle: {
            //   align: "right",
            fontSize: fontSize,
            color: "#fff",
          },
          axisLabel: {
            show: true,
            fontSize: fontSize,
            color: "#fff",
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "#4F6776",
            },
          },
          axisTick: {
            show: true,
            lineStyle: {
              color: "#4F6776",
            },
          },
          splitLine: {
            show: false,
            lineStyle: {
              type: "dotted",
              width: 0.5,
              color: "#4F6776",
            },
          },
        },
        {
          show: option.twoYAxis || false,
          type: "value",
          axisLabel: {
            formatter: "{value} ",
            color: "#ffffff",
            textStyle: {
              fontSize: fontSize,
            },
          },
          name: unit[1] ? "单位：" + unit[1] : "",
          nameGap: $$.transVHFontSize(1.2),
          nameTextStyle: {
            //   align: "right",
            fontSize: fontSize,
            color: "#fff",
          },
          axisLabel: {
            show: true,
            fontSize: fontSize,
            color: "#fff",
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "#4F6776",
            },
          },
          axisTick: {
            show: true,
            lineStyle: {
              color: "#4F6776",
            },
          },
          splitLine: {
            show: false,
            lineStyle: {
              type: "dotted",
              width: 0.5,
              color: "#4F6776",
            },
          },
        },
      ],
      series: series,
    };
    myChart.setOption(myOption, true);
    myChart.off("click");
    myChart.on("click", function (params) {
      var index = datas.map((item) => item.name).indexOf(params.name);
      if (index > -1) {
        params.chartData = datas[index];
      }
      clickFun && clickFun(params);
    });
  }

  function setblBar(id, data) {
    var myCharts = echarts.init($(id)[0]);
    var rightData = [];
    var leftData = [];
    rightData.push(data.right - 0 + (data.left - 0));
    leftData.push(data.left - 0);
    var option = (option = {
      xAxis: {
        type: "value",
        data: ["received", "accountsReceivable"],
        show: false,
      },
      yAxis: {
        type: "category",
        show: false,
      },
      grid: {
        bottom: 0,
        right: 0,
        left: 0,
        top: 0,
      },
      series: [
        {
          name: "已收",
          type: "bar",
          stack: "总量",
          data: leftData,
          barWidth: 12,
          itemStyle: {
            color: "#2F9EFE",
            barBorderRadius: [10, 0, 0, 10],
          },
          label: {
            show: false,
            formatter: "{name| {a} }{value| {c} }",
            align: "left",
            position: [-4, -20],
            rich: {
              value: {
                color: "#2F9EFE",
                fontSize: 18,
                //    fontWeight: 500,
                lineHeight: 10,
              },
              name: {
                color: "#fff",
                fontSize: 16,
                //    fontWeight: 400,
                lineHeight: 10,
              },
            },
          },
        },
        {
          name: "应收",
          type: "bar",
          stack: "总量",
          data: rightData,
          barWidth: 12,
          itemStyle: {
            color: "#FDAE5A",
            barBorderRadius: [0, 10, 10, 0],
          },
          label: {
            show: false,
            formatter: "{name| {a} }{value| {c} }",
            align: "right",
            position: [4, -20],
            rich: {
              value: {
                color: "#FDAE5A",
                fontSize: 18,
                fontWeight: 500,
                lineHeight: 30,
              },
              name: {
                color: "#95A4B3",
                fontSize: 14,
                fontWeight: 400,
                lineHeight: 30,
              },
            },
          },
        },
      ],
    });
    myCharts.setOption(option);
  }

  function PercentCircle(id, data, options, clickFun) {
    var elem = $(id)[0];
    var radius = options.radius || ["60%", "70%"];
    var fontSize = options.fontSize || 20;
    var title = data.value + data.unit;
    var colors = options.colors || { color1: "#FFBE4E", color2: "#FF9A37" };
    var myChart = echarts.getInstanceByDom(elem) || echarts.init(elem);
    var myOption = {
      title: {
        text: title,
        x: "center",
        y: "center",
        textStyle: {
          fontWeight: "normal",
          color: "#fff",
          fontSize: fontSize,
        },
      },
      color: ["#282c40"],
      legend: {
        show: true,
        data: [],
      },
      series: [
        {
          name: "percent",
          type: "pie",
          clockWise: true,
          radius: radius,
          center: ["50%", "50%"],
          itemStyle: {
            normal: {
              label: {
                show: false,
              },
              labelLine: {
                show: false,
              },
            },
          },
          hoverAnimation: false,
          data: [
            {
              value: data.value - 0,
              name: "finished",
              itemStyle: {
                color: {
                  // 完成的圆环的颜色
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: colors.color1 || "#456FFB", // 0% 处的颜色
                    },
                    {
                      offset: 0.5,
                      color: colors.color2 || "#456FFB", // 0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: colors.color2 || "#456FFB", // 100% 处的颜色
                    },
                  ],
                  global: false,
                },
              },
            },
            {
              name: "unfinished",
              value: 100 - data.value,
              itemStyle: {
                color: "rgba(42,69,136,1)",
              },
            },
          ],
        },
      ],
    };
    myChart.setOption(myOption, true);
    myChart.off("click");
    myChart.on("click", function (params) {
      clickFun && clickFun(params);
    });
    function formatData() {
      var data = [
          {
            value: 0,
            name: "finished",
            itemStyle: {
              color: {
                // 完成的圆环的颜色
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "#2380FF", // 0% 处的颜色
                  },
                  {
                    offset: 0.5,
                    color: "#2380FF", // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "#2380FF", // 100% 处的颜色
                  },
                ],
                global: false,
              },
            },
          },
          {
            name: "unfinished",
            value: 0,
            itemStyle: {
              color: "#EBEFFA",
            },
          },
        ],
        title = "";
      let percent = 0,
        total = 0,
        value = 0;
      if (typeof data == "number") {
        value = Number(data);
        if (Math.abs(data) < 1 && Math.abs(data) > 0) {
          total = 1;
          percent = data == 0 ? 0 : (data * 100).toFixed(2);
        } else if (Math.abs(data) < 100 && Math.abs(data) > 1) {
          total = 100;
          percent = data == 0 ? 0 : data.toFixed(2);
        }
      } else {
        value = data.value - 0;
        total = data.total - 0 || 100;
        percent = value == 0 ? 0 : ((value / total) * 100).toFixed(2);
      }
      title = percent + "%" + "\n完成率";
      data[0].value = value;
      data[1].value = total - value;

      return {
        data: data,
        title: title,
      };
    }
  }
  // 多环
  function moreBar(id, data, option, clickFun) {
    var elem = $(id)[0];
    var myChart = echarts.init(elem);
    let color = ["#6d9de0", "#49d896", "#f5d03a", "#f5853a", "#f5503a"];
    var chartData = data.datas;
    var maxNameLength = chartData
      .map((item) => {
        return item.name.length;
      })
      .sort(function (a, b) {
        return b - a;
      })[0];
    var unit = data.unit || "";
    let arrName = [];
    let arrValue = [];
    let sum = 0;
    let pieSeries = [],
      lineYAxis = [];

    // 数据处理
    chartData.forEach((v, i) => {
      arrName.push(v.name);
      arrValue.push(v.value - 0);
      sum = sum + (v.value - 0);
    });
    if (sum == 0) {
      sum = 100;
    }
    // 图表option整理
    chartData.forEach((v, i) => {
      // console.log(v,i, v.value,sum - v.value)
      let chartnewData = chartData.slice(0, i);

      let newValue = chartnewData.reduce((a, b) => {
        return a + b.value;
      }, 0);
      // v.startAngle = newValue / sum * 360
      v.startAngle = newValue == 0 ? 360 : newValue * 360;
      pieSeries.push({
        name: "学历",
        type: "pie",
        clockWise: true,
        hoverAnimation: false,
        radius: [75 - i * 15 + "%", 68 - i * 15 + "%"],
        center: ["30%", "50%"],
        label: {
          show: false,
        },
        startAngle: v.startAngle + 90,
        data: [
          {
            value: v.value - 0,
            name: v.name,
          },
          {
            value: sum - (v.value - 0),
            name: "",
            itemStyle: {
              color: "rgba(0,0,0,0)",
            },
          },
        ],
      });
      pieSeries.push({
        name: "",
        type: "pie",
        silent: true,
        z: 1.3,
        clockWise: true, //顺时加载
        hoverAnimation: false, //鼠标移入变大
        radius: [75 - i * 15 + "%", 68 - i * 15 + "%"],
        // radius: ['50%', '70%'],
        center: ["30%", "50%"],
        label: {
          show: false,
        },
        data: [
          {
            value: sum,
            itemStyle: {
              color: "rgba(16, 70, 99,.2)", //圆环颜色
            },
          },
          {
            value: 0,
            name: "",
            itemStyle: {
              color: "",
            },
          },
        ],
      });
      v.percent = ((v.value / sum) * 100).toFixed(0) + unit;
      lineYAxis.push({
        value: i,
        textStyle: {
          rich: {
            circle: {
              color: color[i],
              padding: [0, 5],
            },
          },
        },
      });
    });

    var myOption = {
      color: option.color || ["#2F9EFE", "#34C39D", "#FDAE5A", "#FF6169", "#8E67FF", "#89D47F"],
      legend: {
        itemWidth: $$.transVHFontSize(1.5),
        itemHeight: $$.transVHFontSize(1.1),
        show: true,
        top: option.legendTop || "middle",
        left: option.legendLeft || "50%",
        itemGap: option.legendItemGap || $$.transVHFontSize(0.25),
        formatter: (name) => {
          return (
            // {name|' + item.name + '}
            "{name|" +
            name +
            "} {value|" +
            chartData.find((item) => {
              return item.name == name;
            }).value +
            unit +
            "}"
          );
        },
        textStyle: {
          fontSize: fontSize,
          color: "#fff",
          rich: {
            name: {
              fontSize: fontSize,
              width: option.nameWidth || maxNameLength * $$.fitFontSize(18),
            },
            value: {
              fontSize: fontSize,
              color: "#fff",
            },
            percent: {},
          },
        },
      },
      grid: {
        left: 0,
        right: 0,
        top: 0,
        bottom: 0,
        containLabel: true,
      },
      yAxis: [
        {
          type: "category",
          inverse: true,
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
          data: lineYAxis,
        },
      ],
      xAxis: [
        {
          show: false,
        },
      ],
      series: pieSeries,
    };

    myChart.off("legendselectchanged");
    myChart.on("legendselectchanged", function (params) {
      var isSelected = params.selected[params.name];
      var title = params.name;
      if (isSelected == false) {
        myChart.dispatchAction({
          type: "legendToggleSelect",
          name: params.name,
        });
        myChart.dispatchAction({
          type: "highlight ",
          name: params.name,
        });
        clickFun && clickFun(params);
      }
    });

    myChart.setOption(myOption);
  }
  function setPie(id, data, option, clickFun) {
    var elem = $(id)[0];
    var myChart = echarts.getInstanceByDom(elem) || echarts.init(elem);
    var datas = data.datas;
    var maxNameLength = datas
      .map((item) => {
        return item.name.length;
      })
      .sort(function (a, b) {
        return b - a;
      })[0];
    var total = 0;
    datas.map((item) => {
      total += item.value;
    });
    var series = [
      {
        type: "pie",
        radius: option.radius || ["35%", "65%"],
        center: option.center || ["20%", "50%"],
        roseType: option.roseType || false,
        name: data.name || "",
        label: {
          show: false,
        },
        labelLine: {
          show: false,
        },
        data: datas,
        hoverOffset: 5,
        minAngle: 5,
        animation: true,
      },
    ];
    if (!option.normalPie) {
      series.push({
        type: "pie",
        radius: option.radius2 || ["35%", "38%"],
        center: option.center || ["20%", "50%"],
        name: "",
        label: {
          show: false,
        },
        labelLine: {
          show: false,
        },
        data: [
          {
            value: 1,
            itemStyle: {
              color: "#fff",
            },
          },
        ],
        hoverAnimation: false,
      });
    }
    var myOption = {
      color: option.color || ["#2F9EFE", "#34C39D", "#FDAE5A", "#FF6169", "#8E67FF", "#89D47F"],
      grid: {
        left: 0,
        right: 0,
        top: 0,
        bottom: 0,
        containLabel: true,
      },
      tooltip: {
        show: true,
        formatter: "{b}<br />数值：{c}<br />占比：{d}%",
        confine: true,
        // padding:0
      },
      legend: {
        // type:datas.length>8?'scroll':'',
        orient: "vertical",
        type: option.type || "",
        top: option.legendTop || "middle",
        left: option.legendLeft || "60%",
        itemWidth: $$.transVHFontSize(1.5),
        itemHeight: $$.transVHFontSize(1.1),
        itemGap: option.legendItemGap || $$.transVHFontSize(0.6),
        padding: 0,
        textStyle: {
          fontSize: fontSize,
          color: "#fff",
          rich: {
            name: {
              fontSize: fontSize,
              width: option.nameWidth || maxNameLength * $$.fitFontSize(18),
            },
            value: {
              fontSize: fontSize,
              color: "#fff",
            },
            percent: {},
          },
        },
        // formatter:datas.length>8?'{name}':
        formatter: function (name) {
          var showValue = option.showValue || false,
            showPercent = option.showPercent || false;
          var index = datas.map((item) => item.name).indexOf(name);
          if (name && index > -1) {
            var value = datas[index].value,
              percent = ((value / total) * 100).toFixed(option.fixedNum || 2);
            return ["{name|" + name + "}", showValue ? "{value|" + (value + (data.unit || "")) + "}" : "", showPercent ? "{percent|" + (percent + "%") + "}" : ""].join("");
          } else {
            return name;
          }
        },
        pageIconSize: $$.transVHFontSize(1),
        pageIconColor: "#2f4554",
        pageIconInactiveColor: "#fff",
        pageTextStyle: {
          fontSize: fontSize,
          color: "#fff",
        },
      },
      series: series,
      // series: [{
      //         type: "pie",
      //         radius: option.radius||['35%', '65%'],
      //         center: option.center||['20%', '50%'],
      //         roseType:option.roseType||false,
      //         name: data.name || '',
      //         label: {
      //             show: false
      //         },
      //         labelLine: {
      //             show: false
      //         },
      //         data: datas,
      //         hoverOffset:5,
      //         minAngle: 5 ,
      //         animation: true ,
      //     },
      //     {
      //         type: "pie",
      //         radius: ['35%', '38%'],
      //         center: option.center||['20%', '50%'],
      //         name: '',
      //         label: {
      //             show: false
      //         },
      //         labelLine: {
      //             show: false
      //         },
      //         data: [{
      //             value: 1,
      //             itemStyle: {
      //                 color: '#fff'
      //             }
      //         }],
      //         hoverAnimation:false
      //     },
      // ]
    };
    myChart.setOption(myOption, true);
    // myChart.off('click');
    // myChart.on('click',function(params){
    //     console.log(params,"puuu")
    //     // clickFun&& clickFun(params)
    // });
    myChart.off("legendselectchanged");
    myChart.on("legendselectchanged", function (params) {
      var isSelected = params.selected[params.name];
      var title = params.name;
      if (isSelected == false) {
        myChart.dispatchAction({
          type: "legendToggleSelect",
          name: params.name,
        });
        myChart.dispatchAction({
          type: "highlight ",
          name: params.name,
        });
        clickFun && clickFun(params);
      }
    });
  }
  function setRadar(id, data, total) {
    var elem = $(id)[0];
    var myChart = echarts.getInstanceByDom(elem) || echarts.init(elem);
    var indicator = data.map((item) => {
      return {
        name: item.name + "(" + (item.value || 0) + ")",
        max: 100,
      };
    });
    var myOption = {
      // backgroundColor:'#000',
      title: {
        text: total || 0,
        left: "center",
        top: "middle",
        textStyle: {
          color: "#fff",
          fontSize: $$.fitFontSize(36),
          fontWeight: "bold",
        },
      },
      legend: {
        show: false,
      },
      radar: {
        shape: "circle",
        radius: "50% ",
        indicator: indicator,
        name: {
          textStyle: {
            color: "#fff",
            fontSize: $$.fitFontSize(18),
          },
        },
        splitLine: {
          lineStyle: {
            color: "#8793a2",
            type: "dotted",
          },
        },
        axisLine: {
          lineStyle: {
            color: "#8793a2",
            type: "dotted",
          },
        },
        splitArea: {
          show: false,
        },
      },
      series: [
        {
          animation: true,
          name: "value",
          type: "radar",
          data: [
            {
              value: data.map((item) => item.value),
              name: "值",
            },
          ],
          itemStyle: {
            color: {
              type: "linear",
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [
                {
                  offset: 0,
                  color: "#1673FF", // 0% 处的颜色
                },
                {
                  offset: 1,
                  color: "#2FCAFD", // 100% 处的颜色
                },
              ],
              global: false, // 缺省为 false
            },
          },
          lineStyle: {
            width: 4,
            color: {
              type: "linear",
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [
                {
                  offset: 0,
                  color: "#1673FF", // 0% 处的颜色
                },
                {
                  offset: 1,
                  color: "#2FCAFD", // 100% 处的颜色
                },
              ],
              global: false, // 缺省为 false
            },
          },
          areaStyle: {
            color: {
              type: "linear",
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [
                {
                  offset: 0,
                  color: "#4FB2F8", // 0% 处的颜色
                },
                {
                  offset: 1,
                  color: "#1170C2", // 100% 处的颜色
                },
              ],
              global: false, // 缺省为 false
            },
          },
        },
      ],
    };
    myChart.setOption(myOption, true);
  }

  function setLine(id, data, option, clickFun) {
    var elem = $(id)[0];
    var myChart = echarts.getInstanceByDom(elem) || echarts.init(elem);
    var datas = data.series,
      series = [],
      unit = data.unit;
    var color = option.color || ["rgba(72,182,255,1)", "#8E67FF", "#2F9EFE"];
    var chartType = "";
    datas.map((item, i) => {
      chartType = item.type || "line";
      series.push({
        animation: true,
        name: item.name,
        stack: item.stack || "",
        type: item.type || "line",
        data: item.data,
        symbol: "circle",
        // symbol: 'emptyCircle',
        symbolSize: 4,
        smooth: option.notSmooth ? false : true,
        barWidth: 10,
        lineStyle: {
          width: 2,
          color: color[i],
        },
        itemStyle: {
          color: color[i],
        },
        areaStyle: {
          show: option.hideArea ? false : true,
          color: color[i],
          opacity: option.hideArea ? 0 : 0.2,
        },
        label: {
          show: option.seriesLabel ? true : false,
          position: "top",
          distance: 1,
          textStyle: {
            color: color[i],
            fontSize: fontSize - 2,
          },
        },
      });
    });
    var myOption = {
      color: color,
      grid: {
        left: "2%",
        right: "6%",
        top: series.length == 1 ? $$.transVHFontSize(1.7 + 1.7) : $$.transVHFontSize(6),
        bottom: "0",
        containLabel: true,
      },
      legend: {
        show: series.length == 1 ? false : true,
        orient: "horizontal",
        top: "top",
        left: "center",
        itemWidth: $$.transVHFontSize(1.2),
        itemHeight: $$.transVHFontSize(0.8),
        itemGap: $$.transVHFontSize(2),
        textStyle: {
          fontSize: fontSize,
          color: "#fff",
        },
      },
      tooltip: {
        show: true,
        trigger: "axis",
        // formatter:  (params)=> {// tooltip的formatter
        //     var relVal = params[0].name
        //     for (var i = 0, l = params.length; i < l; i++) {
        //       let settingUnit = this.option.setting[i].yAxisName;
        //       let unit = settingUnit || this.option.yAxis && this.option.yAxis[params[i].seriesIndex] && this.option.yAxis[params[i].seriesIndex].name || this.option.yAxisName;
        //         relVal += '<br/>' + params[i].marker + params[i].seriesName + ' : ' + params[i].value + (unit||'')
        //     }
        //     return relVal
        // }
      },
      xAxis: [
        {
          type: "category",
          show: true,
          interval: 0,
          boundaryGap: chartType == "bar" ? true : false,
          axisLabel: {
            show: true,
            fontSize: fontSize,
            color: "#fff",
            interval: option.interval || 0,
            rotate: option.xAxisRotate || 0,
            formatter: option.xAxisOverflow
              ? function (params) {
                  return params.length > 3 ? params.substr(0, 2) + "..." : params;
                  return params.split("").join("\n");
                }
              : "{value}",
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "#4F6776",
            },
          },
          axisTick: {
            show: true,
            lineStyle: {
              color: "#4F6776",
            },
          },
          splitLine: {
            show: option["yAxisSplitLineShow"] || false,
            lineStyle: {
              type: "dotted",
              width: 0.5,
              color: "#4F6776",
            },
          },
          data: data.categories,
        },
      ],
      yAxis: {
        show: true,
        type: "value",
        name: unit ? "单位：" + unit : "",
        nameGap: $$.transVHFontSize(1),
        nameTextStyle: {
          //   align: "right",
          fontSize: fontSize,
          color: "#fff",
        },
        axisLabel: {
          show: true,
          fontSize: fontSize,
          color: "#fff",
        },
        axisLine: {
          show: true,
          lineStyle: {
            color: "#4F6776",
          },
        },
        axisTick: {
          show: true,
          lineStyle: {
            color: "#4F6776",
          },
        },
        splitLine: {
          show: option["yAxisSplitLineShow"] || false,
          lineStyle: {
            type: "dotted",
            width: 0.5,
            color: "#4F6776",
          },
        },
      },
      series: series,
    };

    myChart.off("click");
    myChart.on("click", function (params) {
      clickFun && clickFun(params);
    });
    myChart.setOption(myOption, true);
  }

  function setBar(id, data, option, clickFun) {
    var elem = $(id)[0];
    var myChart = echarts.getInstanceByDom(elem) || echarts.init(elem);
    var datas = data.series,
      series = [],
      unit = data.unit;
    var color = option.color || [
      { color2: "#ACCBFF", color1: "#2F9EFE" },
      { color2: "#ACCBFF", color1: "#2FFEAE" },
      { color2: "#ACCBFF", color1: "#FE9F2F" },
    ];
    var chartType = "";
    datas.map((item, i) => {
      chartType = item.type || "line";
      series.push({
        animation: true,
        name: item.name,
        stack: item.stack || "",
        type: "bar",
        data: item.data,
        barWidth: 20,
        itemStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 0,
              color: color[i].color1,
            },
            {
              offset: 1,
              color: color[i].color2,
            },
          ]),
        },
        label: {
          show: option.showLable || false,
          position: "top",
          distance: 1,
          textStyle: {
            color: color[i],
            fontSize: $$.fitFontSize(16),
          },
        },
      });
    });
    var myOption = {
      color: color,
      grid: {
        left: "1%",
        right: 0,
        top: unit ? $$.transVHFontSize(1.5 + 1.7) : 0,
        bottom: "0",
        containLabel: true,
      },
      legend: {
        show: series.length == 1 ? false : true,
        orient: "horizontal",
        top: "top",
        left: "right",
        itemWidth: $$.transVHFontSize(1.2),
        itemHeight: $$.transVHFontSize(0.8),
        itemGap: $$.transVHFontSize(2),
        textStyle: {
          fontSize: fontSize,
          color: "#fff",
        },
      },
      tooltip: {
        show: true,
        trigger: "axis",
        // formatter:  (params)=> {// tooltip的formatter
        //     var relVal = params[0].name
        //     for (var i = 0, l = params.length; i < l; i++) {
        //       let settingUnit = this.option.setting[i].yAxisName;
        //       let unit = settingUnit || this.option.yAxis && this.option.yAxis[params[i].seriesIndex] && this.option.yAxis[params[i].seriesIndex].name || this.option.yAxisName;
        //         relVal += '<br/>' + params[i].marker + params[i].seriesName + ' : ' + params[i].value + (unit||'')
        //     }
        //     return relVal
        // }
      },
      xAxis: [
        {
          type: "category",
          show: true,
          interval: 0,
          boundaryGap: true,
          axisLabel: {
            show: true,
            fontSize: fontSize,
            color: "#fff",
            interval: option.interval || 0,
            rotate: option.xAxisRotate || 0,
            formatter: option.xAxisOverflow
              ? function (params) {
                  return params.length > 3 ? params.substr(0, 2) + "..." : params;
                  return params.split("").join("\n");
                }
              : "{value}",
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "#4F6776",
            },
          },
          axisTick: {
            show: true,
            lineStyle: {
              color: "#4F6776",
            },
          },
          splitLine: {
            show: option["yAxisSplitLineShow"] || false,
            lineStyle: {
              type: "dotted",
              width: 0.5,
              color: "#4F6776",
            },
          },
          data: data.categories,
        },
      ],
      yAxis: [
        {
          show: true,
          type: "value",
          name: unit ? "单位：" + unit : "",
          nameGap: $$.transVHFontSize(1.5),
          nameTextStyle: {
            //   align: "right",
            fontSize: fontSize,
            color: "#fff",
          },
          axisLabel: {
            show: true,
            fontSize: fontSize,
            color: "#fff",
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "#4F6776",
            },
          },
          axisTick: {
            show: true,
            lineStyle: {
              color: "#4F6776",
            },
          },
          splitLine: {
            show: option["yAxisSplitLineShow"] || false,
            lineStyle: {
              type: "dotted",
              width: 0.5,
              color: "#4F6776",
            },
          },
        },
      ],
      series: series,
    };
    myChart.setOption(myOption, true);

    // myChart.off("legendselectchanged");
    // myChart.on("legendselectchanged", function (params) {
    //   var isSelected = params.selected[params.name];
    //   var title = params.name;
    //   if (isSelected == false) {
    //     myChart.dispatchAction({
    //       type: "legendToggleSelect",
    //       name: params.name,
    //     });
    //     myChart.dispatchAction({
    //       type: "highlight ",
    //       name: params.name,
    //     });
    //     clickFun && clickFun(params);
    //   }
    // });

    myChart.off("click");
    myChart.on("click", function (params) {
      clickFun && clickFun(params);
    });
  }

  function setZBData(id, originalData, callback) {
    var data = originalData || {};
    $.each(originalData, function (k, val) {
      
      if($(id + ' [data-key="' + k + '"]') && $(id + ' [data-key="' + k + '"]').length > 0 && k == 'bjl') {
        $(id + ' [data-key="' + k + '"]').html(val || 0);
        
        let value = Math.round(val - 0);
        $(id + ' .num[data-key="' + k + '"]').rollNum({
          deVal: value,
          transToThursand: true,
          // className:'my_scroll_num'
        });
      }else if ($(id + ' [data-key="' + k + '"]') && $(id + ' [data-key="' + k + '"]').length > 0) {
        $(id + ' [data-key="' + k + '"]').html(val || 0);
        $(id + ' .num[data-key="' + k + '"]').rollNum({
          deVal: val - 0,
          transToThursand: true,
          // className:'my_scroll_num'
        });
      }

      
    });
    // $(id+' [data-key]').each(function(i,ele){
    //     var key = $(this).attr('data-key');
    //     $(ele).html(data[key]||0)
    // })

    callback && callback(data);
  }
  function setMapTypeSelects() {
    // 动态生成地图指标
    var type = "main";
    var selectDatas = mapTypes[type],
      html = "";
    $.each(selectDatas, function (i, item) {
      html += `<div class="tab_content_item ${item.value}" >
                        <input type="radio" name="mapType" checked group="mapType" value="${item.value}" />
                        <i class="radio"></i>
                       
                        <span class="map_type_name">${item.name}</span>
                    </div>`;
    });
    $(".chose_box").html(html);
    $('.tab_content_item [name="mapType"]').change(function () {
      //TODO: 切换地图类型
      // return;
      var type = $(".tablist .tab_item.active").attr("data-maptype");

      initMap(type == "lhyg" ? "330000" : "");
      // setMapLevel();
    });
    $(".tab_content_item").eq(0).find('[name="mapType"]').attr("checked", true);
    // setMapLevel();
  }
  function setMapLevel() {
    var type = "main";
    var subType = $('.tab_content_item [name="mapType"]:checked').val();
    if (subType == "cyrrs" || type == "ldmjzz" || type == "dxsjjq") {
      $(".levels_con").hide();
      return;
    } else {
      $(".levels_con").show();
    }
    var selectDatas = mapLevelSelects[type + "_zbajs"],
      html = "";
    if (selectDatas && selectDatas.length > 0) {
      $.each(selectDatas, function (i, item) {
        html += `<div class="item">
                            <i class="rect ${item.class}"></i>
                            <span>${getLevelText(item)}</span>
                        </div>`;
      });
      $(".levels_con").html(html);
    } else {
      $(".levels_con").hide();
    }

    function getLevelText(item) {
      if (item.lt && item.gt) {
        return item.gt + "~" + item.lt + "";
      } else if (item.lt && !item.gt) {
        return item.lt + "以下";
      } else if (!item.lt && item.gt) {
        return item.gt + "以上";
      }
    }
  }
  function initMap(callback) {
    //初始化地图
    myGDMap && myGDMap.clearMap();
    $.get("../json/" + $$.handleQXCode(mapAreaCode) + ".json", function (res) {
      plynDatas = res.map((aoi) => {
        var regEx = /\s+/g;
        var wkt = aoi.wkt.replace(regEx, " ").split(",");
        aoi.wkt = wkt.map((pair) => pair.split(" "));
        return aoi;
      });
      setMapPlyn(plynDatas);
      getPoints();
      callback && callback();
    });
  }
  function getPoints() {
    //获取地图点数据
    myGDMap.off("click");
    // var type = $('.tablist .tab_item.active').attr('data-maptype');
    var type = "main";
    var subType = $('.tab_content_item [name="mapType"]:checked').val();
    var subTypeName = $('.tab_content_item [name="mapType"]:checked').siblings(".map_type_name").html();

    // var params = {
    //     year:commonYear,
    //     aab301:mapAreaCode,
    // }
    // var mapUrl ={
    //     zbajs:"/zjax/admin/Djg/zfjgMapZbaj",
    //     ssjsjccs:"/zjax/admin/Djg/zfjgMapZSsj"
    // };
    // $$.ajaxRequest(ajaxUrl + mapUrl[subType],params,function (res) {
    //     setPoints(res.data,type,subType,subTypeName);
    // });

    $$.ajaxRequest(
      ajaxUrl2 + "/lemis/business/dp/tsInterface",
      {
        method: "speedAndCuttingFour",
        source: 3,
        administrativeDivisionCode: mapAreaCode,
        year: commonYear,
        dType: subType,
        
      },
      function (res) {
        setPoints(res.data, type, subType, subTypeName);
      }
    );

    // 浙江省 指标
    $$.ajaxRequest(
      ajaxUrl2 + "/lemis/business/dp/tsInterface",
      {
        method: "speedAndCuttingNine",
        source: 3,
        administrativeDivisionCode: mapAreaCode,
        year: commonYear,
        dType: subType,
        
      },
      function (res) {
        let data = res.data;
        setZBData(".axzs_box", data,function(){
          $(".axzs_box").off("click").click(function(){
            alertMaptable(data.name, mapAreaCode, commonYear,"","","","","","",1);
        })
        });
      }
    );

    // res = {"data":[
    //     {"aab301":"330100","ctname":"杭州市","lng":"119.553580","lat":"30.025000","value":88.37},
    //     {"aab301":"330200","ctname":"宁波市","lng":"121.509789","lat":"29.868387","value":62.77},
    //     {"aab301":"330300","ctname":"温州市","lng":"120.602112","lat":"27.900574","value":89.19},
    //     {"aab301":"330400","ctname":"嘉兴市","lng":"120.750862","lat":"30.762653","value":80.52},
    //     {"aab301":"330500","ctname":"湖州市","lng":"119.952420","lat":"30.879381","value":93.52},
    //     {"aab301":"330600","ctname":"绍兴市","lng":"120.582115","lat":"29.907116","value":80.75},
    //     {"aab301":"330700","ctname":"金华市","lng":"119.989506","lat":"29.129523","value":90.12},
    //     {"aab301":"330800","ctname":"衢州市","lng":"118.722627","lat":"28.991708","value":79.68},
    //     {"aab301":"330900","ctname":"舟山市","lng":"122.106865","lat":"30.016027","value":92.08},
    //     {"aab301":"331000","ctname":"台州市","lng":"121.108596","lat":"28.901379","value":88.59},
    //     {"aab301":"331100","ctname":"丽水市","lng":"119.321783","lat":"28.151994","value":87.76},
    //     {"aab301":"330000","ctname":"浙江省","lng":"120.153580","lat":"30.287458","value":84}
    // ],"state":"ok"};
    // setPoints(res.data,type,subType,subTypeName);
  }

  // function alertMaptable(title, aab301, subType) {
  //   console.log('-----------');
  //   if (subType == "zbajs") {
  //     //在办案件数
  //     $$.alertTable({
  //       title: title + "  ",
  //       colsData: [
  //         [
  //           { type: "numbers", title: "序号" },
  //           { title: "案件名称", field: "ajname" },
  //           { title: "案件编号", field: "abb016" },
  //           { title: "登记日期", field: "abb277" },
  //           { title: "主办监察员", field: "abb010t" },
  //           { title: "协办监察员", field: "abb011t" },
  //           { title: "所属辖区", field: "aab301s" },
  //           { title: "当前状态", field: "bb1004" },
  //         ],
  //       ],
  //       url: ajaxUrl + "/zjax/admin/Djg/zfjglefttoplist",
  //       where: {
  //         type: "jcaj",
  //         bj: "0",
  //         aab301: aab301 || "",
  //         year: commonYear,
  //       },
  //       pageProp: {
  //         limit: 10,
  //       },
  //       rowClickFun: function (obj) {
  //         alertMapZBAJDetails(obj, aab301);
  //       },
  //     });
  //   } else if (subType == "ssjsjccs") {
  //     // 双随机检查次数
  //     $$.alertTable({
  //       title: title + "  ",
  //       colsData: [
  //         [
  //           { type: "numbers", title: "序号" },
  //           { title: "企业统一信用代码", field: "unicode" },
  //           { title: "任务", field: "taskcode" },
  //           { title: "企业名称", field: "legalentityname" },
  //           { title: "创建时间", field: "createtime" },
  //           { title: "检查完成时间", field: "checkcompletetime" },
  //         ],
  //       ],
  //       url: ajaxUrl + "/zjax/admin/Djg/zfjgMapZSsjList",
  //       where: {
  //         year: commonYear,
  //         aab301: aab301 || "",
  //       },
  //       searchColumn: [
  //         { name: "线索提交时间", field: "aae036", type: "datePicker", range: true, subtype: "date", format: "yyyy年MM月dd日" },
  //         { name: "欠薪发生时间", field: "abb119", type: "datePicker", range: true, subtype: "month", format: "yyyy年MM月" },
  //         { name: "实际用工所在地", field: "aab301", type: "dropdown", dicData: areaSelects },
  //         {
  //           name: "线索状态",
  //           field: "tsflag",
  //           type: "select",
  //           dicData: [
  //             { label: "正在处理", value: "0" },
  //             { label: "已办结", value: "1" },
  //           ],
  //         },
  //         {
  //           name: "反馈行业领域",
  //           field: "isbb17",
  //           type: "select",
  //           dicData: [
  //             { label: "工程建设领域", value: "1" },
  //             { label: "非工程建设领域", value: "0" },
  //           ],
  //         },
  //       ],
  //       pageProp: {
  //         limit: 10,
  //       },
  //       rowClickFun: function (obj) {
  //         alertMapDetails(obj, aab301); //taskId 主键
  //       },
  //     });
  //   }
  // }
  // function alertMapZBAJDetails(obj, aab301) {
  //   var tableColumns = [
  //     [
  //       { title: "案件编号", field: "abb016" },
  //       { title: "基本诉求", field: "aba003" },
  //       { title: "基本案情", field: "abb012" },
  //       { title: "登记日期", field: "abb277" },
  //       { title: "主办监察员", field: "abb010t" },
  //       { title: "协办监察员", field: "abb011t" },
  //       { title: "案由", field: "aba002" },
  //       { title: "投诉人", field: "tsr" },
  //       { title: "被投诉人", field: "btsr" },
  //       { title: "案件名称", field: "ajname" },
  //       { title: "所属辖区", field: "aab301s" },
  //       { title: "当前状态", field: "bb1004" },
  //     ],
  //   ];
  //   var ecm = $$.alert("axzs");
  //   $("#" + ecm).html(`
  //       <div class="title">详情</div>
  //       <div class="table_con">
  //           <div class="model">
  //               <div class="model_title">基本信息</div>
  //               <div class="model_content ztxxTable"></div>
  //           </div>

  //       </div>
  //   `);
  //   //     <div class="model czqk">
  //   //     <div class="model_title">处置情况</div>
  //   //     <div class="model_content jbqkTable"></div>
  //   // </div>
  //   $$.ajaxRequest(
  //     ajaxUrl + "/zjax/admin/Djg/zfjgjcajdetail",
  //     {
  //       id: obj.data.abz001,
  //       year: commonYear,
  //       aab301: aab301,
  //     },
  //     function (res) {
  //       var data = res.data || {};
  //       $$.title2Table("#" + ecm + " .ztxxTable", tableColumns[0], data || {}, 2);
  //       // if(data.yja011-0 == 2){
  //       //     $$.title2Table('#'+ecm+' .jbqkTable', tableColumns[2], data||{},2);
  //       // }else{
  //       //     $('#'+ecm+' .czqk').hide();
  //       // }
  //     }
  //   );
  // }
  // function alertMapDetails(obj, aab301) {
  //   var tableColumns = [
  //     [
  //       { title: "企业统一信用代码", field: "unicode" },
  //       { title: "任务", field: "taskcode" },
  //       { title: "企业名称", field: "legalentityname" },
  //       { title: "创建时间", field: "createtime" },
  //       { title: "检查完成时间", field: "checkcompletetime" },
  //     ],
  //   ];
  //   var ecm = $$.alert("axzs");
  //   $("#" + ecm).html(`
  //           <div class="title">详情</div>
  //           <div class="table_con">
  //               <div class="model">
  //                   <div class="model_title">基本信息</div>
  //                   <div class="model_content ztxxTable"></div>
  //               </div>

  //           </div>
  //       `);
  //   //     <div class="model czqk">
  //   //     <div class="model_title">处置情况</div>
  //   //     <div class="model_content jbqkTable"></div>
  //   // </div>
  //   $$.ajaxRequest(
  //     ajaxUrl + "/zjax/admin/Djg/zfjgMapZSsjDetail",
  //     {
  //       id: obj.data.taskid,
  //       year: commonYear,
  //       aab301: aab301,
  //     },
  //     function (res) {
  //       var data = res.data || {};
  //       $$.title2Table("#" + ecm + " .ztxxTable", tableColumns[0], data || {}, 2);
  //       // if(data.yja011-0 == 2){
  //       //     $$.title2Table('#'+ecm+' .jbqkTable', tableColumns[2], data||{},2);
  //       // }else{
  //       //     $('#'+ecm+' .czqk').hide();
  //       // }
  //     }
  //   );
  // }

  function setPoints(datas, type, subType, subTypeName, tableUrl) {
    //添加地图点
    // datas = datas.filter((item) => item.administrativedivisioncode != mapAreaCode);
    datas=datas
    $.each(datas, function (i, item) {
      var html = `<div class="map_text_con ${subType} ${subType + "_" + item.administrativedivisioncode} ${getPointClass(item.value, type, subType)}">
            <div class="effect_scatter">
                <div class="effect_circle circle"></div>
                <div class="effect_circle effect_circle1"></div>
                <div class="effect_circle effect_circle2"></div>
                <div class="effect_circle effect_circle3"></div>
            </div>
                <div class="area_box">
                    <div class="text">${item.name}</div>
                </div>
                <div class="num_box num white">${item.value}</div>
                <div class="name_box">${subTypeName}</div>
            </div>`;

      // var html = `<div class="map_text_con ${subType} ${(subType+'_'+item.aab301)} ${getPointClass(item.num,type,subType)}">
      //     <div class="effect_scatter">
      //         <div class="effect_circle circle"></div>
      //         <div class="effect_circle effect_circle1"></div>
      //         <div class="effect_circle effect_circle2"></div>
      //         <div class="effect_circle effect_circle3"></div>
      //     </div>
      //     <div class="area_box">
      //         <div class="text">${item.ctname}</div>
      //     </div>
      //     <div class="num_box num white">${item.num}</div>
      //     <div class="name_box">${subTypeName}</div>
      // </div>`
      // <span class="map_unit">万人</span>
      // let html = '<div class="mapIcon mapIcon">' + item.value + '<span class="dw">' + item.ctname + '</span></div>';

      marker = new AMap.Marker({
        // position: new AMap.LngLat(item.lng-0, item.lat-0),
        // content: item.ctname,
        position: new AMap.LngLat(item.lng - 0, item.lat - 0),
        // 将 html 传给 content
        content: html,
        // 以 icon 的 [center bottom] 为原点
        offset: new AMap.Pixel(-18, -15),
        data: item,
      });
      myGDMap.add(marker);
      AMap.event.addListener(marker, "click", function (e) {
        //添加点击事件,传入对象名，事件名，回调函数
        iconClick(e.target.w.data, subType);
        // alertMaptable(subTypeName, e.target.w.data.administrativedivisioncode, subType);
      });
      if (subType == "tjcgl") {
        AMap.event.addListener(marker, "mouseover", function (e) {
          //添加点击事件,传入对象名，事件名，回调函数
          $(".tjcgl_" + e.target.w.data.aab301 + " .name_box").tips(
            {
              title: "调解成功率",
              content: "调解成功案件数/劳动纠纷案件办结总数*100%",
            },
            {
              width: 200,
              position: "right",
              trigger: "click",
              class: "my_tooltip my_tooltip_r",
              margin: 0,
            }
          );
        });
      }
    });

    //
  }
  function getPointClass(value, type, subType) {// 转换点样式
    var levelTypeClass = '';
    var levels = mapLevelSelects["main_zbajs"];
     
    if (levels && levels.length > 0) {
        $.each(levels, function (i, item) {
            if (item.lt && item.gt && (value < item.lt && value >= item.gt)) {
                levelTypeClass = 'map_text_con_' + item.class;
            } else if (item.lt && !item.gt && value < item.lt) {
                levelTypeClass = 'map_text_con_' + item.class;
            } else if (!item.lt && item.gt && value >= item.gt) {
                levelTypeClass = 'map_text_con_' + item.class;
            }
        });
    }

    return levelTypeClass;
}
  function setMapPlyn(datas) {
    // 生成地图区块
    mapPlyns = [];
    $.each(datas, function (i, item) {
      // var index = plynDatas.map(item=>item.aoiid).indexOf(item.aab301);
      // if(index > -1){
      plynItem = item;
      plynItem.areaCode = item.aoiid;
      plyn = new AMap.Polygon({
        bubble: true,
        fillOpacity: 0.8,
        fillColor: mapColor.normal, //填充颜色
        strokeColor: "#8BB3E3", //轮廓线
        strokeWeight: 0.1,
        path: plynItem.wkt,
        map: myGDMap,
        data: plynItem,
        cont: [plynItem.x, plynItem.y],
      });
      // }
      mapPlyns.push(plyn);
      AMap.event.addListener(plyn, "click", function (e) {
        //添加点击事件,传入对象名，事件名，回调函数
        areaClick(e.target.w.data, e.target.w.cont, e);
        setModelMain(true);
      });
    });
    myGDMap.off('zoomchange').on('zoomchange', function (e,b,c) {
      //TODO: 监听地图缩放
      if(isMapClick){// 下钻，切换区县
          isMapClick = false;
          return;
      }else{
          var zoom = myGDMap.getZoom();
          if(mapLastZoom != zoom){//避免重复触发
              mapLastZoom = zoom;
              var mouseMapArea = '';
              if(mouseLnglat){// 判断鼠标当前在那个地区
                  $.each(mapPlyns,function(i,plynItem){
                      if(plynItem.contains(mouseLnglat)){
                          mouseMapArea = plynItem.w.data;
                          plynItem.setOptions({
                              fillColor: mapColor.active
                          })
                      }else{
                          plynItem.setOptions({
                              fillColor: mapColor.normal
                          })
                      }
                  })
              }
              var mapLevel = getAreaLevel(mouseMapArea.aoiid);
              console.log(zoom,"zoom")
              if (zoom == 7) {
                  mapAreaCode = '330000';
                  myGDMap.setCenter( [120.153576,29.289523])
                  $('.map_tit .loc').eq(0).nextAll().remove();
                  setModelMain()
                  // changeModel();
              } else if (zoom == 9) {
                  var areacode,center;
                  if (mapLevel == 2){//当前为区县，缩小
                      areacode = $('.map_tit .loc').eq(1).attr('data-i');
                      center = ($('.map_tit .loc').eq(1).attr('data-lnglat')).split(',');
                      $('.map_tit .loc').eq(1).nextAll().remove();
                      mapAreaCode = areacode;
                      myGDMap.setCenter(center);
                      setModelMain(true)
                      // changeModel(true);
                  }else{//放大
                      if(mouseMapArea && mapAreaCode != mouseMapArea.aoiid){
                          areacode = mouseMapArea.aoiid;
                         
                          center = [mouseMapArea.x,mouseMapArea.y];
                           $('.map_tit').append('<span  data-i="'+areacode+'" data-lnglat="'+(center.join(','))+'"   class="loc" >  '+mouseMapArea.name+'</span>')
                          mapAreaCode = areacode;
                          myGDMap.setCenter(center);
                          setModelMain()
                          // changeModel();
                      }
                  }
              }else if (zoom == 11){
                  areacode = mouseMapArea.aoiid;
                  center = [mouseMapArea.x,mouseMapArea.y];
                  mapAreaCode = areacode;
                  // if($('.map_tit .loc').length>=3 ){//区县，不增加
                  //     $('.map_tit .loc').eq(2).attr('data-i',areacode);
                  //     $('.map_tit .loc').eq(2).attr('data-lnglat',center.join(','));
                  //     $('.map_tit .loc').eq(2).html(' '+mouseMapArea.name);
                  // }else{
                  //     $('.map_tit').append('<span  data-i="'+areacode+'" data-lnglat="'+(center.join(','))+'"   class="loc">  '+mouseMapArea.name+'</span>')
                  // }
                  myGDMap.setCenter(center);
                  // setModelMain(true)
              }
          }
      }
  });
  }

  function areaClick(data, cont, ev) {
    //TODO: 地区点击事件
    isMapClick = true;
    $.each(mapPlyns, function (i, plyn) {
      plyn.setOptions({
        fillColor: mapColor.normal,
      });
    });
    mapActiveAreaData = data;
    var mapLevel = getAreaLevel(data.areaCode);
    var zoom = myGDMap.getZoom();
    ev.target.setOptions({
      fillColor: mapColor.active,
    });
    var option = ev.target.getOptions();
    var type = $(".tablist .tab_item.active").attr("data-maptype");
    if (type == "lhyg") {
      if (zoom >= 8 && zoom <= 20) {
        if (mapLevel == 1) {
          //市级
          mapAreaCode = data.areaCode;
          myGDMap.setZoomAndCenter(9, [data.x, data.y]);
          if ($(".map_tit .loc").length >= 2) {
            //区县，不增加
            $(".map_tit .loc").eq(1).attr("data-i", mapAreaCode);
            $(".map_tit .loc").eq(1).attr("data-lnglat", [data.x, data.y].join(","));
            $(".map_tit .loc")
              .eq(1)
              .html(" " + data.name);
          } else {
            $(".map_tit").append('<span  data-i="' + mapAreaCode + '" data-lnglat="' + [data.x, data.y].join(",") + '"   class="loc">  ' + data.name + "</span>");
          }
          setModelMain(true);
        }
      }
    } else {
      if (zoom >= 8 && zoom <= 20) {
        if (mapLevel == 1) {
          //市级
          mapAreaCode = data.areaCode;
          myGDMap.setZoomAndCenter(9, [data.x, data.y]);
          $(".map_tit").append('<span  data-i="' + mapAreaCode + '" data-lnglat="' + [data.x, data.y].join(",") + '"  class="loc">  ' + data.name + "</span>");
          setModelMain();
        } else if (mapLevel == 2) {
          //区县
          if (mapAreaCode == data.areaCode) {
            if (isMapScale) {
              // 第二次点击，放大
              isMapScale = false;
              myGDMap.setZoomAndCenter(11, [data.x, data.y]);
            } else {
              // 第二次点击，缩小
              isMapScale = true;
              myGDMap.setZoomAndCenter(9, [data.x, data.y]);
              ev.target.setOptions({
                fillColor: mapColor.normal,
              });
              // $('.map_tit .loc').eq(1).nextAll().remove();
            }
          } else {
            //首次点击，切换数据
            mapAreaCode = data.areaCode;
            isMapScale = true;
            if ($(".map_tit .loc").length >= 3) {
              //区县，不增加
              $(".map_tit .loc").eq(2).attr("data-i", mapAreaCode);
              $(".map_tit .loc").eq(2).attr("data-lnglat", [data.x, data.y].join(","));
              $(".map_tit .loc")
                .eq(2)
                .html(" " + data.name);
            } else {
              $(".map_tit").append('<span  data-i="' + mapAreaCode + '" data-lnglat="' + [data.x, data.y].join(",") + '"   class="loc">  ' + data.name + "</span>");
            }
            mapAreaCode = data.areaCode;
            myGDMap.setZoomAndCenter(9, [data.x, data.y]);
            setModelMain(true);
          }
        }
      }
    }
  }

  function iconClick(data, type) {
    alertMaptable(data.name, data.administrativedivisioncode, commonYear,"","","","","","",1);

    //地区点击事件
  }

  function getAreaLevel(areaCode) {
    //获取地图层级
    areaCode += "";
    if (areaCode.length > 6) {
      return 3;
    } else if (areaCode.length == 6) {
      if (areaCode.substr(2) == "0000") {
        return 0;
      } else if (areaCode.substr(4) == "00") {
        return 1;
      } else {
        return 2;
      }
    }
  }
});
